<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <title>register</title>
    <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/other.css">

    <script src="../js/move.js"></script>
    <script src="../js/main.js"></script>
    <script src="../js/jquery.cookie.js"></script>
    <script src="../js/js.cookie.js"></script>
</head>
<body style="height: 838px;">
<div id="doc">
    <!---->
    <div class="reg-page">
        <div id="regHeader">
            <div class="header-content">
<span class="switch-login">
<a href="login.html" title="登录" target="_blank">登录</a>
</span>
                <a href="http://i.360.cn/reg?src=pcw_qikoo&amp;destUrl=http%3A%2F%2Fmall.360.com%2Fuser" title="">
                    <span class="logo"></span>
                </a>
<span class="page-title">
<a href="#" title="注册帐号">注册帐号</a>
</span>
            </div>
            <!---->



        </div>
        <!---->
        <div class="reg-content">
            <div id="regWrap" style="display:block;">
                <div class="reg-title">
                    注册360帐号
                </div>
                <!---->
                <div class="quc-sign-up-wrapper quc-wrapper quc-page">
                    <div class="quc-mod-sign-up quc-clearfix">
                        <div class="quc-main">
                            <div class="quc-tip-wrapper quc-global-error"><p class="quc-tip quc-tip-error"></p></div>
                            <!---->
                            <form class="quc-form" method="post" action="https://i.360.cn/signUp/dosignUpAccount">
                                <div>
                                    <p class="quc-field quc-field-mobile quc-input-long"><span class="quc-fixIe6margin"><label class="quc-label"></label></span><span class="quc-input-bg"><input id="reg-mobile" class="quc-input quc-input-mobile" type="tel"   maxlength="11" onblur="checkPhoneNum()" placeholder="请输入要注册的手机号"></span></p>
                                    <span class="quc-tip"></span>
                                    <!---->
                                    <p class="quc-field quc-field-password quc-input-long"><span class="quc-fixIe6margin"><label class="quc-label"></label></span><span class="quc-input-bg"><input id="reg-pwd" class="quc-input quc-input-password" type="password"  maxlength="20" onblur="checkPwd()" placeholder="密码长度要在8~16之间"></span></p>
                                    <span class="quc-tip"></span>

                                    <!---->
                                    <p class="quc-field quc-field-captcha quc-input-short" style="display: block;"><img class="quc-captcha-img quc-captcha-change" alt="验证码" title="点击更换" tabindex="99" src="http://passport.360.cn/captcha.php?m=create&amp;app=i360&amp;scene=strictreg&amp;userip=&amp;level=default&amp;sign=5a63a7&amp;r=1469494663&amp;_=1469494666254"><span class="quc-input-bg"><input id="reg-yzm" class="quc-input quc-input-captcha" type="password" name="captcha" maxlength="20" onblur="checkYzm()"  placeholder="请再次输入密码"></span></p>
                                    <span class="quc-tip"></span>
                                    <!---->
                                    <p class="quc-field quc-next-step quc-clearfix"><a href="##" class="quc-nextAndGet-sms-token" id="reg-ok">确定</a></p>
                                    <!---->
                                </div>

                                <p  class="quc-field quc-field-licence"><label><span >点击“确定”，即表示您已同意并愿意遵守<a class="quc-link" href="http://i.360.cn/pub/protocol.html" target="_blank">《360用户服务条款》</a></span></label></p>

                            </form>


                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!---->
    </div>

    <!---->
    <div class="other-info">
<span class="gray-line">
<a href="http://i.360.cn/findpwd/customerhelper?sb_param=ae3d87c12f4d05deff7c0ef397d90d4b" title="帮助中心" target="_blank">帮助中心</a>
</span>
<span>
<a href="http://i.360.cn/complaint?sb_param=8a0a4ba4ec48382b7710939e482629ff" title="立即申诉" target="_blank">立即申诉</a>
</span>
    </div>
    <!---->
    <div id="ft">Copyright©2005-<span id="currentYear">2016</span> 360.CN All Rights Reserved 360安全中心
        <p><a target="_blank" href="http://www.miibeian.gov.cn?sb_param=823462c0945b5df9035bd898efffee05">京ICP证080047号[京ICP备08010314号-6] </a></p>
        <p>
            <a style="color:#999;" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11000002000006&amp;sb_param=4f7e54ee07f0db35aec5b0e6f7671933" target="_blank">
                <img class="wangan" src="http://p4.qhimg.com/t01d8eda6e551cf2615.png">京公网安备 11000002000006号</a>
        </p>
    </div>
</div>
<!--tip start-->
<div class="mod-dialog">
    <div class="dialog-nav">
        <span class="dialog-title">提示</span>
        <a href="#" onclick="return false" class="dialog-close"></a>
    </div>
    <div class="dialog-main"><div class="dialog-content"><p id="tip-content">购买数量为1到20之间的整数!</p></div><div class="dialog-console clearfix_new"><a class="console-btn-confirm" href="login.html" target="_blank">去登录</a></div></div></div>

<div class="mod-dialog-bg" style=""></div>
<script>
    function tip(content){
        $('#tip-content').text(content);
        $('.mod-dialog-bg').css("display","block");
        $('.mod-dialog').css("display","block");

        $('.dialog-close').click(function(e){
            //清空填写的注册信息  这时候数据已经存进cookie
            $('#reg-mobile').val('');
            $('#reg-pwd').val('');
            $('#reg-yzm').val('');

            //$(this).parent().parent().parent().find('#reg-mobile').val('');
            //隐藏
            $(this).parent().parent().parent().find('.mod-dialog-bg').hide();
            $(this).parent().parent('.mod-dialog').css("display","none");

        })
        $('.console-btn-confirm').click(function(e){
            $(this).parent().parent().parent().parent().find('.mod-dialog-bg').css("display","none");
            $(this).parent().parent().parent('.mod-dialog').css("display","none");
        })
    }
</script>
<!--tip over-->

<script type="text/javascript">
    var isExisted = false;//设置一个全局性变量 记录输入名是否已经存在
    var regPhoneNum=/^1[3|4|5|7|8]\d{9}$/;

    $('#reg-mobile').keyup(function(){
        this.value=this.value.replace(/[^0-9-]+/, '');//只能输入数字
    })

    function exist(){
        var usn = document.getElementById('reg-mobile').value;

        // 先取cookie里数据 registerUsers 存储格式username,pwd:username2,pwd2:username3,pwd3
        var users = getCookie("registerUsers");
        // 按照储存时的格式解析
        users = users.split(":");
        //判断是否已经注册过
        for(var i = 0; i < users.length; i++){
            var user = users[i].split(",")
            // 逐条匹配， 有用户名和密码都匹配上的话，登录成功，跳转到首页
            if(usn === user[0]){
                isExisted = true;
            }
        }
    }
    /*
    * 用户名逻辑
    * */

    function checkPhoneNum() {
        var usn = document.getElementById('reg-mobile').value;
        //首先清空下面的提示
        $($('.quc-tip')[2]).html('');
        $($('.quc-tip')[3]).html('');
        isExisted = false;//每次blur都初始为假
        exist()
        /*
        下面进行各种逻辑判断
        * */
        //判断输入是否为空
        if(usn == ''){
            $($('.quc-tip')[1]).html('手机号输入为空');
            return false;
        }
        //判断输入格式是否正确
        if(regPhoneNum.test(usn) == false){
            $($('.quc-tip')[1]).html('手机号码格式不正确');
            return false;
        }
        //判断是否已经存在
        if (isExisted){//已经存在
            $($('.quc-tip')[1]).html('用户名已存在，请重新输入');
            return false;
        }
        //正确时的判断
        $($('.quc-tip')[1]).html('');
        return true;
    }

    /*
    * 密码逻辑
    * */
    function checkPwd(){

        $($('.quc-tip')[3]).html('');//在判断是首先清空下面逻辑判断的提示
        var pwd=document.getElementById("reg-pwd").value;
        /*
        * 各种判断 注意顺序
        * */
        //exist();
        if(!checkPhoneNum()){
            return false;
        }
      /*  if(isExisted){
            return false;
            $($('.quc-tip')[1]).html('用户名已存在，请重新输入');

        }
        if(regPhoneNum.test(usn) == false){
            $($('.quc-tip')[1]).html('手机号码格式不正确');
            return false;
        }
        if (usn == ''){
            $($('.quc-tip')[1]).html('手机号输入为空');
            return false;
        }*/
        //
        if (pwd == '') {
            $($('.quc-tip')[2]).html('密码不能为空');
            return false;
        }
        if (pwd.length < 8 || pwd.length > 16) {
            $($('.quc-tip')[2]).html('长度要在8~16之间');
            return false;
        }
        if (/[^\x00-\x7f]/.test(pwd)) {
            $($('.quc-tip')[2]).html('密码编码格式不合规范');
            return false;
        }
        if (/^\d{8,16}$/.test(pwd)) {
            $($('.quc-tip')[2]).html('不能全部为数字');
            return false;
        }
        if (/^[^A-Za-z0-9]+$/.test(pwd)) {
            $($('.quc-tip')[2]).html('不能以非法字符开头');
            return false;
        }
        if (/^[A-Za-z]{8,16}$/.test(pwd)) {
            $($('.quc-tip')[2]).html('不能全部为字母');
            return false;
        }
        $($('.quc-tip')[2]).html('');
        return true;
    }
    /**/
    function checkYzm(){
        if(!checkPhoneNum()){
            return false;
        }
        if(!checkPwd()){return false;}

        var pwdAgain = document.getElementById("reg-yzm").value;
        var pwd = document.getElementById("reg-pwd").value;
        if(pwdAgain == "") {
            $($('.quc-tip')[3]).html('请再次输入密码');
            return false;
        }
        if(pwdAgain != pwd){
            $($('.quc-tip')[3]).html('密码不一致，请重新输入');
            return false;
        }
        //密码输入一致，验证成功
        $($('.quc-tip')[3]).html('');
        return true;
    }

    document.getElementById("reg-ok").onclick = function () {
        if(!checkPhoneNum()){
            return false;
        }
        if(!checkPwd()){return false;}
        if(!checkYzm()){return false;}
        /*
        * 成功 存入cookie*/
        var usn = document.getElementById('reg-mobile').value;
        var pwd=document.getElementById("reg-pwd").value;
        // 获取已存在的用户数据
        var users = getCookie("registerUsers");
        if (users !== "") {//根据格式进行拼接
            users += ":"
        }
        // 将新注册的用户添加到用户数据中
        users += usn + "," + pwd;
        // 放入cookie保存
        setCookie("registerUsers", users, 7);
        // 注册成功后跳转到登录界面
        tip(usn + ",恭喜您注册成功!")
       // window.location.href = "login.html";
       /*  setTimeout( function(){
         window.location.href = "login.html";
         }, 2000);*/
        return true;
    }
</script>
</body>
</html>